﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Utils.Wpf.Converters
{
	public class MarginConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			switch (parameter.ToString())
			{
				case "Top":
					return new Thickness(0, System.Convert.ToDouble(value), 0, 0);
				case "Bottom":
					return new Thickness(0, 0, 0, System.Convert.ToDouble(value));
				case "Left":
					return new Thickness(System.Convert.ToDouble(value), 0, 0, 0);
				case "Rigth":
					return new Thickness(0, 0, System.Convert.ToDouble(value), 0);
				default:
					return null;
			}
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			switch (parameter.ToString())
			{
				case "Top":
					return ((Thickness)value).Top;
				case "Bottom":
					return ((Thickness)value).Bottom;
				case "Left":
					return ((Thickness)value).Left;
				case "Rigth":
					return ((Thickness)value).Right;
				default:
					return null;
			}
		}
	}
}
